// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  return cloud.callFunction({
    name: "model_ticket",
    data: {
      op: "update",
      id: event.ticket_id,
      ticket_number: event.ticket_number,
      u_id: event.user_id,
      i_id: event.institution_id,
      g_id: event.good_id,
      s_id: event.student_id,
      status: event.status,
      express: event.express,
      express_number: event.express_number,
      detail: event.detail
    }
  }).then(res => {
    if (res.result.stats.updated == 1) {
      return cloud.callFunction({
        name: "model_ticket",
        data: {
          op: "select",
          key: "_id",
          value: event.ticket_id,
        }
      }).then(res => {
        return res.result.data;
      })
    } else {
      return 0;
    }
  })
}